package org.fujay.langchain4jserver.domain.application.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.fujay.langchain4jserver.domain.application.vo.AppId;
import org.fujay.langchain4jserver.domain.application.vo.UsageMetrics;
import org.fujay.langchain4jserver.domain.application.vo.UsageStatsId;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 应用使用统计实体
 * fixme 统计纬度增加 embeddingTokens
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AppUsageStats {

    private AppId appId;

    /**
     * 统计日期
     */
    private LocalDate date;

    /**
     * 当日请求总次数
     */
    private Long requestCount;

    /**
     * 当日使用的 Prompt Token 总数
     */
    private Long promptTokens;

    /**
     * 当日生成的 Completion Token 总数
     */
    private Long completionTokens;

    /**
     * 当日使用的总 Token 数 (prompt + completion)
     */
    private Long totalTokens;

    public static AppUsageStats create(AppId appId, LocalDate date) {
        return new AppUsageStats(appId, date, 0L, 0L, 0L, 0L);
    }

    public void incrementUsage(long requests, long promptTokens, long completionTokens) {
        this.requestCount += requests;
        this.promptTokens += promptTokens;
        this.completionTokens += completionTokens;
        this.totalTokens = this.promptTokens + this.completionTokens;
    }
    /*fixme 简单实现*/
    public static AppUsageStats load(UsageStatsId statsId, AppId appId, LocalDate date, UsageMetrics metrics, LocalDateTime updateTime) {

        return create(appId, date);
    }

}
